<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 200px;
      height: 200px;
      background-color: aquamarine;
      margin: 50px auto;
    }
    .animate-enter{
      transform: translateX(-500px) rotate(360deg) scale(0.1);
      opacity: 0;
    }
    .animate-enter-active,.animate-leave-active{
      transition: all .5s;
    }
    .animate-leave-to{
      transform: translateY(500px) rotate(-360deg) scale(0.1);
      opacity: 0;
    }
  </style>
</head>

<body>
  <div id="app">
    <button @click="isShow = !isShow">{{isShow ? '隐藏': '显示'}}</button>
    <!-- tranmsition组件通过name属性定义动画 -->
    <!-- .name-enter:组件进入时动画
        .name-enter-active:组件过渡属性 在这里定义transition属性
        .name-leave-to:组件结束时的动画
        通过mode：out-in和in-out来控制动画执行的先后顺序
    -->
    <transition name="animate" mode="out-in">
      <div class="box" v-if="isShow" key="1"></div>
      <div class="box" style="background-color: brown;" v-else key="2"></div>
    </transition>
  </div>
  <script src="../vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        isShow: true
      },
    })
  </script>
</body>

</html>